home *** CD-ROM | disk | FTP | other *** search
/ Singles Flirt Up Your Life! (German) / Singles Flirt Up Your Life.iso / data1.cab / Statemachine / toilet.lua < prev    next >
Text File  |  2004-01-29  |  4KB  |  114 lines

  1. -- toilet state machine
  2.  
  3. beginStateMachine()
  4.  
  5.     onMsg("buildMenu", function(msg)
  6.     
  7.         if (repairMenu()) then return end
  8.     
  9.         -- build the pie menu
  10.         clearPieMenu();
  11.         local button ;
  12.         button = addPieMenuButton("pm_sitToilet", "sitToilet");
  13.         button.addDescription(ACTIVITY, "sitToilet");
  14.         -- button.addIcon("guiIconHygiene");
  15.         
  16.         if (this.getDirtiness() > 0.01) then 
  17.             button = addPieMenuButton("pm_clean", "clean");
  18.             button.addDescription(ACTIVITY, "clean");         
  19.             button.addDescription(ACTIVITY, "improveObjectTidiness");            
  20.             button.addIcon("guiIconWohnung");
  21.         end;
  22.         -- button.addIcon("guiIconWohnung");
  23.     end )
  24.     
  25.     -- sit on toilet
  26.     onMsg("sitToilet", function(msg)
  27.         -- get the game object server
  28.         local gameObjectServer = getGameObjectServer();
  29.         -- get character who initiated this action
  30.         local character = getStateObjectFromID(msg.sender);
  31.         -- if this is broken: abort characters action
  32.         if abortIfBroken(character) then return end;        
  33.         -- walk to the closest action point
  34.         local actionPoint = character.getClosestFreeActionPointToClickPoint(this, {"sit"});
  35.         if (actionPoint) then
  36.             -- get the walk state object
  37.             local wso = character.walkSO;
  38.             if (wso.walkToActionPoint(actionPoint)) then
  39.                 wso.queueStateMachine("toiletChar.sitDown", this);
  40.             else
  41.                 print("no path found");
  42.                 instantAbort(character, EMOTICON_NOPATH, "emoThink")
  43.             end
  44.         else
  45.             print("no action point found");
  46.             instantAbort(character, EMOTICON_CANNOT, "emoThink")
  47.         end
  48.     end )
  49.     
  50.     
  51.     -- clean on toilet
  52.     onMsg("clean", function(msg)
  53.         -- get the game object server
  54.         local gameObjectServer = getGameObjectServer();
  55.         -- get character who initiated this action
  56.         local character = getStateObjectFromID(msg.sender);
  57.         -- if this is broken: abort characters action
  58.         if abortIfBroken(character) then return end;
  59.         -- if character is too unhappy: abort characters action
  60.         if instantAbortIfUnhappy(character, "clean", this) then return end;
  61.         -- walk to the closest action point
  62.         local actionPoint = character.getClosestFreeActionPointToClickPoint(this, {"clean"});
  63.         if (actionPoint) then
  64.             -- get the walk state object
  65.             local wso = character.walkSO;
  66.             if (wso.walkToActionPoint(actionPoint)) then
  67.                 wso.queueStateMachine("toiletChar.cleanStart", this);
  68.             else
  69.                 print("no path found");
  70.                 --queueNextClean(character);
  71.                 instantAbort(character, EMOTICON_NOPATH, "emoThink")
  72. --                character.setEmoticon(EMOTICON_NOPATH, EMOTICON_DELAY);
  73. --                sendMsg("emoThink", character.walkSO);
  74.             end
  75.         else
  76.             print("no action point found");
  77.             --queueNextClean(character);
  78.             instantAbort(character, EMOTICON_CANNOT, "emoThink")
  79. --            character.setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  80. --            sendMsg("emoThink", character.walkSO);
  81.         end
  82.     end )
  83.     
  84.     
  85.     
  86.     -- repair
  87.     onMsg("repair", function(msg)
  88.     
  89.         print("onMsg repair");
  90.         -- get character who initiated this action
  91.         local character = getStateObjectFromID(msg.sender);
  92.         -- walk to the closest action point
  93.         local actionPoint = character.getFreeActionPoint(this, "repair");
  94.         -- get the walk state object
  95.         local wso = character.walkSO;
  96.         if (actionPoint) then
  97.             -- create state machine contexts
  98.             local wsoContext = StateMachineContext();
  99.             -- store the action point
  100.             wsoContext.storeData("actionPointName", actionPoint.getName());
  101.             if (wso.walkToActionPoint(actionPoint)) then
  102.                 wso.queueStateMachine("repairChar.repairStart", this, wsoContext);
  103.             else
  104.                 print("no path found");
  105.                 instantAbort(character, EMOTICON_NOPATH, "emoThink")
  106.             end
  107.         else
  108.             print("no action point found");
  109.             instantAbort(character, EMOTICON_CANNOT, "emoThink")
  110.         end
  111.     end )
  112.                         
  113. endStateMachine()
  114.